package com.zl.roomdesign.main

import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.zl.core.MainApp
import com.zl.core.extend.inflate
import com.zl.roomdesign.R
import kotlinx.android.synthetic.main.item_img_list.view.*


/**
 * Created by zhangli on 2018/5/6,14:58<br/>
 */
class ImageListAdapter(private val list: MutableList<ImgEntity>, private var onItemClick: ((ViewHolder) -> Unit)? = null) : RecyclerView.Adapter<ImageListAdapter.ViewHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = parent.inflate(R.layout.item_img_list, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount() = list.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.itemView.setOnClickListener {
            onItemClick?.invoke(holder)
        }

        if (list[position].check) {
            holder.itemView.checkImg.visibility = View.VISIBLE
        } else {
            holder.itemView.checkImg.visibility = View.GONE
        }

        Glide.with(holder.itemView)
                .load(list[position].fileName)
                .into(holder.itemView.img)
    }

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view)

}